﻿<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="BarCodePrintOut.aspx.cs" Inherits="BarCodePrintOut" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>条码打印输出</title>
    <script src="js/jquery/jquery-1.8.1.min.js" type="text/javascript"></script>
    <script src="js/extTools.js" type="text/javascript"></script>
    <script src="js/config.js" type="text/javascript"></script>
    <link href="css/ExtStyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        //var printClient = new ActiveXObject("KM_ClientPrintActiveX.KMPrintControl");
        var PrintPreview = function (grid) {
            //console.log(grid.store.data.items);
            //console.log(grid.store.data.items.length);
            //console.log(grid.store.data.items[0].data.STYLECODE);

            if (!!window.ActiveXObject || "ActiveXObject" in window) {
            }
            else {
                Ext.Msg.alert("温馨提示", "目前只支持IE浏览器！请选择IE浏览器进行打印！");
                return false;
            }
            var fileUrl = $('#PrintTemplateFile').val();
            if (grid.getSelectionModel().getCount() == 0) {
                Ext.Msg.alert("温馨提示", "请选择需要打印的行！");
                return false;
            }
            if (fileUrl == "") {
                Ext.Msg.alert("温馨提示", "请选择需要打印的模板！");
                return false;
            }

            //console.log(grid.getSelectionModel().selected.items);
            //console.log(grid.getSelectionModel().selected.items[0].data);
            var printData = grid.getSelectionModel().selected.items[0].data;

            //根据款号StyleCode循环读取出所有的尺码SizeName 
            var allTableData = grid.store.data.items;
            //console.log(allTableData);
            var SizeNameNum = "";
            for (var i = 0; i < allTableData.length; i++) {
                if (printData.STYLECODE == allTableData[i].data.STYLECODE) {
                    if (SizeNameNum.indexOf(" " + allTableData[i].data.SizeName + " ") > -1) {
                    }
                    else {
                        SizeNameNum = SizeNameNum + " " + allTableData[i].data.SizeName + " ";
                    }
                }
            }

            //充绒量描述
            var SpareField1 = "";
            if (printData.Remark1 != null && printData.Remark1 != "") {
                SpareField1 = "充绒量：" + printData.Remark1;
            }

            var JsonData = {
                list: [{
                    "Address": printData.Address,
                    "BillNo": printData.BillNo,
                    "ColorName": printData.COLORNAME,
                    "Certification": printData.Certification,
                    "CompanyID": printData.CompanyID,
                    "ForeignName": printData.FOREIGNNAME,
                    "FactCode": printData.FactCode,
                    "LinkMan": printData.LinkMan,
                    "MaterialShortName": printData.MATERIALSHORTNAME,
                    "MatVendor": printData.MatVendor,
                    "Material": printData.Material,
                    "MaterialCode": printData.MaterialCode,
                    "MobilePhone": printData.MobilePhone,
                    "RetailPrice": printData.RETAILPRICE == null ? "" : printData.RETAILPRICE.toString(),
                    "Remark1": printData.Remark1,
                    "SendCheckNo": printData.SENDCHECKNO,
                    "ShoetreeNo": printData.SHOETREENO,
                    "StuffName": printData.STUFFNAME,
                    "StyleCode": printData.STYLECODE,
                    "SUBSeries": printData.SUBSERIES,
                    "SexName": printData.SexName,
                    "SizeNameNum": SizeNameNum,
                    "SizeName": printData.SizeName,
                    "VendCustName": printData.VendCustName,
                    "BarCode": printData.barcode,
                    "BillDate": printData.billdate,
                    "CNStateName": printData.cnstatename,
                    "ColorCode": printData.colorcode,
                    "KindName": printData.kindname,
                    "Qty": printData.qty == null ? "" : printData.qty.toString(),
                    "SeasonName": printData.seasonname,
                    "VendCustCode": printData.vendcustcode,
                    "YearNo": printData.yearno == null ? "" : printData.yearno.toString(),
                    "PackageBarCode": printData.PackageBarCode, //包装条码
                    "RuleNum": printData.RuleNum, //内件数
                    "PackageType": printData.PackageType, //包装类型
                    "SpareField1": SpareField1,
                    "SpareField2": "2",
                    "SpareField3": "3",
                    "SpareField4": "4",
                    "SpareField5": "5",
                    "SpareField6": "6",
                    "SpareField7": "7",
                    "SpareField8": "8",
                    "SpareField9": "9"
                }]
            };
            var strJson = JSON.stringify(JsonData);
            //alert(fileUrl);
            //alert(strJson); //codebase="ActiveX/setup.exe"
            //printClient.PrintPreview(strJson, fileUrl);
            OpenPrintPreview(strJson, fileUrl)
            return true;
        }
        //直接以组件ID进行调用
        function OpenPrintPreview(strJson, fileUrl) {
            helloworld.PrintPreview(strJson, fileUrl);
        }
        //正常关闭网页推出进程
        window.onbeforeunload = onbeforeunload_handler;
        function onbeforeunload_handler() {
            helloworld.BTQuit();
        }
        
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Crisp" />
        <ext:Viewport ID="Viewport1" runat="server">
            <LayoutConfig>
                <ext:HBoxLayoutConfig Align="Stretch" />
            </LayoutConfig>
            <Defaults>
                <ext:Parameter Name="margin" Value="0" Mode="Value" />
            </Defaults>
            <Items>
                <ext:Panel ID="Panel1" runat="server" Flex="1" Layout="FitLayout">
                    <Items>
                        <ext:Panel ID="Panel2" runat="server" Layout="BorderLayout">
                            <Items>
                                <ext:Panel Region="West" ID="Panel3" runat="server" Split="true" Collapsible="true"
                                    Collapsed="false" Title="统计过虑条件" Icon="ApplicationFormEdit" PaddingSummary="5px 5px 0"
                                    Width="280" ButtonAlign="Center" Layout="BorderLayout">
                                    <Items>
                                        <ext:FormPanel ID="ColumPanel" runat="server" Layout="Column" Reference="form" Region="Center"
                                            Collapsible="true" ButtonAlign="Center" Title="基本条件" Margin="3" BodyStyle="overflow:auto;">
                                            <Items>
                                                <ext:MultiCombo runat="server" ID="txtYearNo" FieldLabel="年份" Padding="3" LabelWidth="80" DisplayField="YearNo" ValueField="YearNo">
                                                    <Store>
                                                        <ext:Store ID="Store_YearNo" runat="server">
                                                            <Model>
                                                                <ext:Model ID="Model_YearNo" runat="server">
                                                                    <Fields>
                                                                        <ext:ModelField Name="YearNo" />
                                                                    </Fields>
                                                                </ext:Model>
                                                            </Model>
                                                        </ext:Store>
                                                    </Store>
                                                </ext:MultiCombo>
                                                <ext:MultiCombo runat="server" ID="txtSeasonName" FieldLabel="季节" Padding="3" LabelWidth="80" DisplayField="SeasonName" ValueField="SeasonName">
                                                    <Store>
                                                        <ext:Store ID="Store_SeasonName" runat="server">
                                                            <Model>
                                                                <ext:Model ID="Model_SeasonName" runat="server">
                                                                    <Fields>
                                                                        <ext:ModelField Name="SeasonName" />
                                                                    </Fields>
                                                                </ext:Model>
                                                            </Model>
                                                        </ext:Store>
                                                    </Store>
                                                </ext:MultiCombo>
                                                <ext:DateField runat="server" ID="txtDateBegin" FieldLabel="开始日期" Padding="3" LabelWidth="80" ></ext:DateField>
                                                <ext:DateField runat="server" ID="txtDateEnd" FieldLabel="结束时间" Padding="3" LabelWidth="80" ></ext:DateField>
                                                <ext:TextField runat="server" ID="txtVendcustCode" FieldLabel="供应商编号" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtVendCustName" FieldLabel="供应商名称" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtStyleCode" FieldLabel="款号" Padding="3" LabelWidth="80" />
                                                <ext:MultiCombo runat="server" ID="txtKindName" FieldLabel="类别" Padding="3" LabelWidth="80" DisplayField="KindName" ValueField="KindName">
                                                    <Store>
                                                        <ext:Store ID="Store_KindName" runat="server">
                                                            <Model>
                                                                <ext:Model ID="Model_KindName" runat="server">
                                                                    <Fields>
                                                                        <ext:ModelField Name="KindName" />
                                                                    </Fields>
                                                                </ext:Model>
                                                            </Model>
                                                        </ext:Store>
                                                    </Store>
                                                </ext:MultiCombo>
                                                <ext:TextField runat="server" ID="txtBillNo" FieldLabel="单号" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtFactCode" FieldLabel="制单号" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtMatVendor" FieldLabel="物料供应商" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtMatBillCode" FieldLabel="物料采购单号" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtMaterialCode" FieldLabel="货号" Padding="3" LabelWidth="80" />
                                                <ext:TextField runat="server" ID="txtBarCode" FieldLabel="条码" Padding="3" LabelWidth="80" />

                                            </Items>
                                        </ext:FormPanel>
                                    </Items>

                                    <BottomBar>
                                        <ext:Toolbar ID="Toolbar1" runat="server">
                                            <Items>
                                                <ext:Button ID="Button10" runat="server" Text="统计" OnDirectClick="BtnQureyUser4" IconCls="find24" Scale="Small" IconAlign="Left" Cls="x-btn-as-arrow">
                                                    <DirectEvents>
                                                        <Click Timeout="200000">
                                                            <EventMask ShowMask="true" Msg="加载中...">
                                                            </EventMask>
                                                        </Click>
                                                    </DirectEvents>
                                                </ext:Button>
                                                <ext:Button ID="Button3" runat="server" Text="导出" OnDirectClick="BtnOutExcel" Visible="true" IconCls="import24" Scale="Small"
                                                    IconAlign="Left" Cls="x-btn-as-arrow">
                                                    <DirectEvents>
                                                        <Click Timeout="900000">
                                                            <EventMask ShowMask="true" Msg="玩命下载中...">
                                                            </EventMask>
                                                        </Click>
                                                    </DirectEvents>
                                                </ext:Button>
                                            </Items>
                                        </ext:Toolbar>
                                    </BottomBar>

                                </ext:Panel>
                                <ext:TabPanel ID="TabPanel1" runat="server" Region="Center">
                                    <Items>
                                        <ext:GridPanel ID="GridPanel1" runat="server" TitleAlign="Center" Title="条码打印输出" ActiveIndex="0">
                                            <TopBar>
                                                <ext:Toolbar ID="Toolbar2" runat="server" Layout="Container">
                                                    <Items>
                                                        <ext:Toolbar ID="Toolbar8" runat="server">
                                                            <Items>
                                                                <ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="排序区域:" Reorderable="false" />
                                                                <ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server" Reorderable="false" />
                                                                <ext:ToolbarTextItem ID="ToolbarTextItem2" runat="server" Text="IE浏览器支持客户端打印:" Reorderable="false" />
                                                                <ext:Container ID="DownloadPrintPlug" runat="server">
                                                                    <Content>
                                                                        <span style="color:Blue">选择需要打印的行，浏览选择本地打印模板，进行打印</span>
                                                                        <a href="ActiveX/KM_ClientPrintActiveX.rar" style="color:Red;">需要在客户端进行打印预览请先下载安装setup.exe</a>
                                                                    </Content>
                                                                </ext:Container>
                                                            </Items>
                                                        </ext:Toolbar>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                            <Store>
                                                <ext:Store ID="Store3" runat="server" PageSize="100" OnReadData="RefreshDataSet" OnSubmitData="Store4_Submit">
                                                    <Model>
                                                        <ext:Model ID="Model8" runat="server" IDProperty="条码打印输出编号">
                                                            <Fields>
                                                                <ext:ModelField Name="CompanyID" ServerMapping="CompanyID" />
                                                                <ext:ModelField Name="FactCode" ServerMapping="FactCode" />
                                                                <ext:ModelField Name="BillNo" ServerMapping="BillNo" />
                                                                <ext:ModelField Name="cnstatename" ServerMapping="cnstatename" />

                                                                <ext:ModelField Name="billdate" ServerMapping="billdate" />
                                                                <ext:ModelField Name="vendcustcode" ServerMapping="vendcustcode" />
                                                                <ext:ModelField Name="VendCustName" ServerMapping="VendCustName" />
                                                                <ext:ModelField Name="MaterialCode" ServerMapping="MaterialCode" />

                                                                <ext:ModelField Name="yearno" ServerMapping="yearno" />
                                                                <ext:ModelField Name="seasonname" ServerMapping="seasonname" />
                                                                <ext:ModelField Name="MatVendor" ServerMapping="MatVendor" />
                                                                <ext:ModelField Name="MATERIALSHORTNAME" ServerMapping="MATERIALSHORTNAME" />

                                                                <ext:ModelField Name="kindname" ServerMapping="kindname" />
                                                                <ext:ModelField Name="STYLECODE" ServerMapping="STYLECODE" />
                                                                <ext:ModelField Name="COLORNAME" ServerMapping="COLORNAME" />
                                                                <ext:ModelField Name="SizeName" ServerMapping="SizeName" />

                                                                <ext:ModelField Name="SexName" ServerMapping="SexName" />
                                                                <ext:ModelField Name="Material" ServerMapping="Material" />
                                                                <ext:ModelField Name="colorcode" ServerMapping="colorcode" />
                                                                <ext:ModelField Name="SHOETREENO" ServerMapping="SHOETREENO" />

                                                                <ext:ModelField Name="Certification" ServerMapping="Certification" />
                                                                <ext:ModelField Name="barcode" ServerMapping="barcode" />
                                                                <ext:ModelField Name="RETAILPRICE" ServerMapping="RETAILPRICE" />
                                                                <ext:ModelField Name="STUFFNAME" ServerMapping="STUFFNAME" />

                                                                <ext:ModelField Name="Remark1" ServerMapping="Remark1" />
                                                                <ext:ModelField Name="SENDCHECKNO" ServerMapping="SENDCHECKNO" />
                                                                <ext:ModelField Name="SUBSERIES" ServerMapping="SUBSERIES" />
                                                                <ext:ModelField Name="FOREIGNNAME" ServerMapping="FOREIGNNAME" />

                                                                <ext:ModelField Name="qty" ServerMapping="qty" />
                                                                <ext:ModelField Name="LinkMan" ServerMapping="LinkMan" />
                                                                <ext:ModelField Name="Address" ServerMapping="Address" />
                                                                <ext:ModelField Name="MobilePhone" ServerMapping="MobilePhone" />

                                                                <ext:ModelField Name="PackageBarCode" ServerMapping="PackageBarCode" />
                                                                <ext:ModelField Name="RuleNum" ServerMapping="RuleNum" />
                                                                <ext:ModelField Name="PackageType" ServerMapping="PackageType" />

                                                            </Fields>
                                                        </ext:Model>
                                                    </Model>
                                                </ext:Store>
                                            </Store>
                                            <ColumnModel>
                                                <Columns>
                                                    <ext:RowNumbererColumn ID="RowNumbererColumn4" runat="server" />
                                                    <ext:Column ID="Column1" runat="server" Text="品牌" DataIndex="CompanyID" Width="80" />
                                                    <ext:Column ID="Column2" runat="server" Text="制单号" DataIndex="FactCode" Width="180" />
                                                    <ext:Column ID="Column3" runat="server" Text="单号" DataIndex="BillNo" Width="180" />
                                                    <ext:Column ID="Column4" runat="server" Text="单据状态" DataIndex="cnstatename" Width="80" />

                                                    <ext:Column ID="Column5" runat="server" Text="开单日期" DataIndex="billdate" Width="120" />
                                                    <ext:Column ID="Column6" runat="server" Text="供应商编号" DataIndex="vendcustcode" Width="80" />
                                                    <ext:Column ID="Column7" runat="server" Text="供应商名称" DataIndex="VendCustName" Width="150" />
                                                    <ext:Column ID="Column8" runat="server" Text="货号" DataIndex="MaterialCode" Width="150" />

                                                    <ext:Column ID="Column9" runat="server" Text="年份" DataIndex="yearno" Width="80" />
                                                    <ext:Column ID="Column10" runat="server" Text="季节" DataIndex="seasonname" Width="80" />
                                                    <ext:Column ID="Column11" runat="server" Text="物料供应商" DataIndex="MatVendor" Width="120" />
                                                    <ext:Column ID="Column12" runat="server" Text="货品简称" DataIndex="MATERIALSHORTNAME" Width="80" />

                                                    <ext:Column ID="Column13" runat="server" Text="类别" DataIndex="kindname" Width="80" />
                                                    <ext:Column ID="Column14" runat="server" Text="款号" DataIndex="STYLECODE" Width="150" />
                                                    <ext:Column ID="Column15" runat="server" Text="颜色名称" DataIndex="COLORNAME" Width="80" />
                                                    <ext:Column ID="Column16" runat="server" Text="尺码" DataIndex="SizeName" Width="80" />

                                                    <ext:Column ID="Column17" runat="server" Text="性别" DataIndex="SexName" Width="80" />
                                                    <ext:Column ID="Column18" runat="server" Text="物料" DataIndex="Material" Width="80" />
                                                    <ext:Column ID="Column19" runat="server" Text="色号" DataIndex="colorcode" Width="80" />
                                                    <ext:Column ID="Column20" runat="server" Text="型号" DataIndex="SHOETREENO" Width="80" />

                                                    <ext:Column ID="Column21" runat="server" Text="合格证" DataIndex="Certification" Width="80" />
                                                    <ext:Column ID="Column22" runat="server" Text="条码" DataIndex="barcode" Width="180" />
                                                    <ext:Column ID="Column23" runat="server" Text="吊牌价" DataIndex="RETAILPRICE" Width="80" />
                                                    <ext:Column ID="Column24" runat="server" Text="物料成份" DataIndex="STUFFNAME" Width="250" />

                                                    <ext:Column ID="Column25" runat="server" Text="充绒量" DataIndex="Remark1" Width="80" />
                                                    <ext:Column ID="Column26" runat="server" Text="执行标准" DataIndex="SENDCHECKNO" Width="200" />
                                                    <ext:Column ID="Column27" runat="server" Text="安全技术类别" DataIndex="SUBSERIES" Width="200" />
                                                    <ext:Column ID="Column28" runat="server" Text="洗涤标准" DataIndex="FOREIGNNAME" Width="200" />

                                                    <ext:Column ID="Column29" runat="server" Text="销售数量" DataIndex="qty" Width="80" />
                                                    <ext:Column ID="Column30" runat="server" Text="联系人" DataIndex="LinkMan" Width="100" />
                                                    <ext:Column ID="Column31" runat="server" Text="收货地址" DataIndex="Address" Width="150" />
                                                    <ext:Column ID="Column32" runat="server" Text="电话" DataIndex="MobilePhone" Width="120" />

                                                    <ext:Column ID="Column33" runat="server" Text="包装条码" DataIndex="PackageBarCode" Width="180" />
                                                    <ext:Column ID="Column34" runat="server" Text="内件数" DataIndex="RuleNum" Width="80" />
                                                    <ext:Column ID="Column35" runat="server" Text="包装类型" DataIndex="PackageType" Width="80" />
                                                </Columns>
                                            </ColumnModel>
                                            <BottomBar>
                                                <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                                                    <Items>
                                                        <ext:Label ID="Label2" runat="server" Text="每页显示:" />
                                                        <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                                                        <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                                                            <Items>
                                                                <ext:ListItem Text="100" />
                                                                <ext:ListItem Text="200" />
                                                                <ext:ListItem Text="500" />
                                                                <ext:ListItem Text="1000" />
                                                            </Items>
                                                            <SelectedItems>
                                                                <ext:ListItem Value="100" />
                                                            </SelectedItems>
                                                            <Listeners>
                                                                <Select Handler="#{GridPanel1}.store.pageSize = parseInt(this.getValue(), 10); #{GridPanel1}.store.reload();" />
                                                            </Listeners>
                                                        </ext:ComboBox>

                                                        <ext:Container ID="lblKMPrint" runat="server">
                                                            <Content>
                                                                <div>请选择打印模板:</div>
                                                            </Content>
                                                        </ext:Container>
                                                        <ext:Container ID="conKMPrint" runat="server">
                                                            <Content>
                                                                <input id="PrintTemplateFile" type="file" />
                                                            </Content>
                                                        </ext:Container>
                                                        <ext:Button ID="btnKMPrint" runat="server" Text="打印" Icon="Printer">
                                                            <Listeners>
                                                                <Click Handler="PrintPreview(#{GridPanel1})" />
                                                            </Listeners>
                                                        </ext:Button>

                                                    </Items>
                                                    <Plugins>
                                                        <ext:ProgressBarPager ID="ProgressBarPager1" runat="server" />
                                                    </Plugins>
                                                </ext:PagingToolbar>
                                            </BottomBar>
                                        </ext:GridPanel>
                                    </Items>
                                </ext:TabPanel>
                            </Items>
                        </ext:Panel>
                    </Items>
                </ext:Panel>
                <ext:Hidden ID="ActState" runat="server" ClientIDMode="Static" Text="Edit" />
            </Items>
        </ext:Viewport>
    </div>
    </form>
    <div style="visibility:hidden">
        <object id="helloworld" classid="clsid:AAABBBCC-D8CB-44B9-BD8C-F7D8348F6DFE"></object>
    </div>
</body>
</html>

